<?php
require_once "weixin_info.php";//å¾®ä¿¡æŽˆæƒèŽ·å–ç”¨æˆ·å¤´åƒç­‰ä¿¡æ?
require_once "config.php";
require_once "jssdk.php";
$jssdk = new JSSDK();
$signPackage = $jssdk->GetSignPackage();
$id = $_GET['id'];
$u_id = !empty($id) ? $id : $_SESSION['Member_info'][0]['id'];
if(!empty($u_id)){
    $sql = $mysql->query("select * from dyspw_member where id=".$u_id);//è§†é¢‘
    $member_info = $sql->fetch_all(MYSQLI_ASSOC);
}else{
    $member_info = $_SESSION['Member_info'];
}
$sql = $mysql->query("select * from dyspw_weblink where u_id=".$u_id." ORDER BY posttime DESC");//è§†é¢‘
$rows = $sql->fetch_all(MYSQLI_ASSOC);
if($member_info[0]['is_vip'] == 3){
    $explore_sql = $mysql->query("select * from dyspw_weblink where shop_id=".$u_id." ORDER BY posttime DESC");//拍客拍摄作品
    $explore = $explore_sql->fetch_all(MYSQLI_ASSOC);
}
$link_sql = $mysql->query("select * from dyspw_like where uid=".$u_id." and state = 1");//å–œæ¬¢
$like = $link_sql->fetch_all(MYSQLI_ASSOC);
$user_sql = $mysql->query("select * from dyspw_userfavorite where uid=".$u_id." and isshow = 1");//æ”¶è—
$user = $user_sql->fetch_all(MYSQLI_ASSOC);
$foll_sql = $mysql->query("select * from dyspw_follow where fans_id=".$u_id);//å…³æ³¨
$foll = $foll_sql->fetch_all(MYSQLI_ASSOC);
$fans_sql = $mysql->query("select * from dyspw_follow where u_id=".$u_id);//ç²‰ä¸
$fans = $fans_sql->fetch_all(MYSQLI_ASSOC);
if($member_info[0]['is_vip'] == 0 && !empty($member_info[0]['shop_son_id'])){
    $shop_son_sql = $mysql->query("select * from dyspw_member where id=".$member_info[0]['shop_son_id']);//è§†é¢‘
    $shop_son = $shop_son_sql->fetch_all(MYSQLI_ASSOC);
    if($shop_son[0]['is_vip'] == 3){
        $shop_son_id = $member_info[0]['shop_son_id'];
    }
}
if(!empty($shop_son_id)){
    $goods_sql = $mysql->query("select * from dyspw_goods where u_id=".$shop_son_id ." ORDER BY time DESC");//ç²‰ä¸
    $goods = $goods_sql->fetch_all(MYSQLI_ASSOC);
}else{
    $goods_sql = $mysql->query("select * from dyspw_goods where u_id=".$u_id ." ORDER BY time DESC");//ç²‰ä¸
    $goods = $goods_sql->fetch_all(MYSQLI_ASSOC);
}
$user_arr = array();
foreach ($user as $key => $val) {
    $web_sql = $mysql->query("select * from dyspw_weblink where id=".$val['aid']);
    $array = $web_sql->fetch_all(MYSQLI_ASSOC);
    if(!empty($array)){
        $user_arr[] = $array[0];
    }
}
// print_r($goods);exit;
$like_count = 0;
foreach ($rows as $key => $val) {
    $web_sql = $mysql->query("select * from dyspw_like where weblinkid=".$val['id']);
    $array = $web_sql->fetch_all(MYSQLI_ASSOC);
    $like_count =  $like_count + count($array);
}
?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <title>个人中心</title>
    <link rel="stylesheet" href="css/core.css">
    <script src="js/jquery-2.2.4.min.js" type="text/javascript"></script>
    <script src="js/jquery.cookie.js" type="text/javascript"></script>
    <script src="js/layer/layer.js" type="text/javascript"></script>
    <script src="js/masonry.pkgd.min.js" type="text/javascript"></script>
    <script src="js/imagesloaded.pkgd.min.js" type="text/javascript"></script>
    <script src="js/dsbridge.js" type="text/javascript"></script>
    <style media="screen">
            <?php if($member_info[0]['is_vip'] == 3){?>
                .grls-info-box{background: url(images/mem_shop.png) center center no-repeat}
            <?php }else{ ?>
                .grls-info-box{background:  url(images/mem_geren.png) center center no-repeat;}
            <?php } ?>
            .grls-menu-box ul li.cur div{background-image: url("./images/user_menu_bg.png");}
    </style>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?cb5d49b07e0a753dc8ee27ba2c73495d";
  var s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(hm, s);
})();
</script>
</head>
<body>
<section style="padding-bottom:50px;">
    <div class="main" style="width:90%;">

		<div class="grls-info-box cl" style="padding-bottom:0px;">
            <div class="" style="display: inline-block; width:100%;">
                <div class="grls-avatar-box">
                    <a href="shop_edit.php"><img src="<?php echo $member_info[0]['avatar'] ?>" /></a>
                </div>
                <div class="grls-desc-box" style="position: relative;">
                    <?php if(empty($id)){?><a href="address_setup.php"><img src="images/mem_setup.png" alt="" style="width: 20px;position: absolute;right: 0px;top: 7px;"></a><?php  } ?>
                    <a href="shop_edit.php"><h2 style="<?php if(!empty($id)){echo 'background:none';} ?>"><?php echo $member_info[0]['username'] ?></h2></a>
                    <p><?php echo $member_info[0]['intro'] ?></p>
                    <div class="btn-box cl">
                        <!-- <a href="#"><img src="images/header-search.png">æŸ¥æ‰¾</a> -->
                        <a href="#" style="float:left;"><?php if($member_info[0]['is_vip'] == 3 ){echo "商户";}elseif ($member_info[0]['is_vip'] == 2) {echo "个人";}elseif ($member_info[0]['is_vip'] == 1) {echo "拍客";}else{echo "游客";}?></a>
                        <?php if(empty($id)){ ?>
                            <a style="float:left; margin-left:20px;" href="#"><img src="images/sys.png">扫一扫</a>
                        <?php  } ?>
                    </div>
                </div>
            </div>
            <p style="    line-height: 40px;padding-left: 10px;">
                <span style="margin-right: 10px;font-size: 12px;color: white;"><em><?php echo $like_count; ?></em> 获赞</span>
                <a href="follow.php<?php if(!empty($id)){ echo '?id='.$id;} ?> ">
                    <span style="margin-right: 10px;font-size: 12px;color: white;"><em><?php echo count($foll); ?></em> 收藏</span>
                    <span style="font-size: 12px;color: white;"><em><?php echo count($fans); ?></em> 粉丝</span>
                </a>
            </p>
		</div>
        <?php if(empty($id)){?>
            <div class="grls-menu-box">
                <ul class="cl">
<!--                    <li class="cur"><div style=""> <a href="https://5p8.fyh5p8.com/xiaochengxu/fenlei.php"><img src="images/icon_fl.png" /></a></div>分类</li>-->
<!--                    <li><div><img src="images/icon_qb.png" /></div>钱包</li>-->
<!--                    <li><div><img src="images/icon_kf.png" /></div>客服</li>-->
                    <li class="cur"> <div style=""> <a href="https://5p8.fyh5p8.com/xiaochengxu/fenlei.php"><img src="images/icon_fl.png" /></a></div>分类</li>
                    <li><a href="wallet.php"><div><img src="images/icon_qb.png" /></div>钱包</a></li>
                    <?php if($member_info[0]['is_vip'] == 3){?>
                        <li><a href="shop_edit.php"><div><img src="images/icon_sz.png" /></div>商铺设置</a></li>
                    <?php }else{ ?>
                        <li><a href="shop_edit.php"><div><img src="images/icon_sz.png" /></div>用户设置</a></li>
                    <?php } ?>
                    <!-- <li><div><a href="http://console.nuoyun.tv/Mobile/Index/index"><img src="images/icon_bf.png" /></a></div>直播</li> -->
                </ul>
            </div>

            <?php } ?>
		<div class="grls-banner-box" style="    margin-top: 10px;">
            <a href="recharge.php"><img src="images/grls_banner.png" /></a>
		</div>

		<div class="grls-spjx-box" >


            <h2 class="cl"><font>商品精选</font><p>Product selection</p>
                <?php if($member_info[0]['is_vip'] == 3 || $member_info[0]['is_vip'] == 2){?>
                    <?php if(empty($id)){?><a href="goods_edit.php" style="    display: inline-block;float: right;font-size: 14px;border: 1px solid #C79400;line-height: 30px;padding: 0px 10px;border-radius: 6px;background: #C79400;color: #fff;margin-top: 5px;">添加商品</a><?php } ?>
                <?php } ?>
             </h2>
			<div class="spjx-box">
                <ul class="cl">
                    <?php if(!empty($goods)){foreach ($goods as $key => $val) { if($key < 4){?>
                        <li>
                            <a href="goods_info.php?id=<?php echo $val['id'];?>">
                                <img src="<?php echo $val['img'] ?>" />
                                <span style="text-align: left;float: left;">原价:<?php echo $val['money'] ?><br/ ><em style="font-size: 14px;color: red;">团购价:<?php echo $val['group_money'] ?></em></span>
                                <p class="title"><?php echo $val['title'] ?></p>
                                <p><?php echo $val['details']; ?></p>
                            </a>
                        </li>
                    <?php }} ?>
                    <?php if($member_info[0]['is_vip'] == 3 || $member_info[0]['is_vip'] == 2){?>
                        <?php if(empty($id)){?><li style="padding: 0px;"><a href="goods_edit.php" style="    display: block;width: 100px;"><img src="images/add_goods.png" alt=""></a></li><?php } ?>
                    <?php }} ?>
				</ul>
			</div>
		</div>



        <style>
            .navigationBox{background: #3f79f3;border-radius: 5px;color: #fff;padding:15px 8px;height: auto;overflow: hidden}
            .navigationBox img{float: left;width: 20px;}
            .navigationBox p{float: left;margin-left: 5px;height: auto;overflow: hidden}
            .navigationBox a{float:right;height: auto;overflow: hidden;background: #fff;color: #000;border-radius: 5px;padding: 3px 10px;margin-top:3px}
        </style>
        <div id='container1' style="display:none"></div>
        <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=d021bae86db1d54dddc4071a5123749c&plugin=AMap.Geocoder"></script>
        <script type="text/javascript">
            var ipBool=false;
            var lng,lat;
            AMap.plugin('AMap.Geolocation', function() {
                var geolocation = new AMap.Geolocation({
                    enableHighAccuracy: true,
                    timeout: 10000,
                    buttonOffset: new AMap.Pixel(10, 20),
                    zoomToAccuracy: true,
                    buttonPosition: 'RB'
                });
                geolocation.getCurrentPosition();
                AMap.event.addListener(geolocation, 'complete', onComplete);
                AMap.event.addListener(geolocation, 'error', onError);
                function onComplete (result) {
                    lng=result.position.getLng();
                    lat=result.position.getLat();
                    <?php if($member_info[0]['shop_lng'] && $member_info[0]['shop_lat']){?>
                    ipBool=true;
                    var p1 =  new AMap.LngLat(lng, lat);
                    var p2 =  new AMap.LngLat(<?php echo $member_info[0]['shop_lng']?>, <?php echo  $member_info[0]['shop_lat']?>);
                    var distance = Math.round(p1.distance(p2));
                    $(".navigationBox p font").html(distance);
                    <?php }?>
                }

                function onError (data) {
                    // alert(JSON.stringify(data));
                }
            });

            function navigation() {
                if(window.navigator.userAgent == 'AndroidNative'){
                    dsBridge.call("mapSite", {lng: "<?php echo $member_info[0]['shop_lng']?>", lat: "<?php echo $member_info[0]['shop_lat']?>", name: "<?php echo $member_info[0]['shop_add']?>"});
                } else if (window.navigator.userAgent == 'IosNative') {
                    dsBridge.call("mapSite", {lng: "<?php echo $member_info[0]['shop_lng']?>", lat: "<?php echo $member_info[0]['shop_lat']?>", name: "<?php echo $member_info[0]['shop_add']?>"});
                } else {
                    if(ipBool){
                        window.location.href="http://uri.amap.com/navigation?from="+lng+","+lat+"&to=<?php echo $member_info[0]['shop_lng']?>,<?php echo  $member_info[0]['shop_lat']?>&mode=car&name='<?php echo $member_info[0]['shop_add']?>'&src=nyx_super";
                    }else {
                        <?php if($member_info[0]['shop_lng'] && $member_info[0]['shop_lat']){?>
                        alert('定位信息获取失败，请查看GPS是否开启');
                        <?php }else{?>
                        alert('商家位置信息未完善');
                        <?php }?>
                    }
                }
            }
        </script>

        <div class="navigationBox">
            <img src="./images/dingwei.png">
            <p><?php echo $member_info[0]['shop_add']?><br>
                距您<font>10000</font>米
            </p>
            <a onclick="navigation()">导航</a>
        </div>




        <div class="video-nav-box grls cl">
            <?php if($member_info[0]['is_vip'] == 3 || (!empty($member_info[0]['shop_son_id']) and !empty($shop_son_id))){ ?>
                <style media="screen">
                    .video-nav-box.grls a{width: 25%!important;}
                </style>
                <a href="mem_goods.php<?php if(!empty($id)){ echo '?id='.$id;} ?>" class="cur">商品 <?php echo count($goods); ?></a>
            <?php    } ?>
			<a href="member.php<?php if(!empty($id)){ echo '?id='.$id;} ?>   " >作品 <?php echo count($rows); ?>  </a>
			<a href="mem_collection.php<?php if(!empty($id)){ echo '?id='.$id;} ?>" >收藏<?php echo count($user_arr); ?></a>
            <a href="mem_like.php<?php if(!empty($id)){ echo '?id='.$id;} ?>" >喜欢 <?php echo count($like); ?></a>
		</div>

		<div class="video-box grls" id="Collection">
			<ul class="cl grid">
                <li class="grid-sizer"></li>
                <?php if(!empty($goods)){ ?>
                    <?php foreach ($goods as $k=>$v){?>
                        <li class="video-box-item">
                            <a class="goods_link" href="goods_info.php?id=<?php echo $v['id'];?>" >
                                <?php if(empty($id)){?>
                                <div class="" style="position: relative;">
                                    <p style="position: absolute;top: 5px;float:right;width:100%;">
                                        <span class="del_goods" web_id="<?php echo $v['id'];?>"><img style="width:30px;" src="images/delite.png" alt=""></span>
                                        <span class="up_goods"  web_id="<?php echo $v['id'];?>" style="float:right;" >
                                            <img style="width:30px;" src="images/update.png" alt="">
                                        </span>
                                    </p>
                                </div>
                                <?php } ?>
                                <img  src="<?php echo $v['img'];?>" class="" style="max-height: 150px">
                                <h2 style="font-size: 11px;height: 40px"><?php echo $v['title']?>
                                    <span style="display: inline-block;float: right;">原价:<?php echo $v['money']?><em style="font-size: 13px;color: red;margin-left: 5px;">团购价:<?php echo $v['group_money']?></em></span>
                                </h2>
                                <div class="video-desc">
                                    <div class="fl">
                                        <img src="<?php echo $v['u_avatar']?>" /><?php echo $v['u_name']?>
                                    </div>
                                     <em>库存<?php echo $v['stock'] ? :0 ?></em>
                                </div>
                            </a>
                        </li>
                        <?php }?>
                <?php } ?>
                <?php if(empty($id)){?>
                <li class="video-box-item" style="height: 298px;line-height: 298px;text-align: center;font-size: 16px;"><a href="goods_edit.php<?php if(!empty($shop_son_id)){echo '?shop_son_id='.$shop_son_id;}?>"><p style="font-size: 16px;color: #C79400;"><span>+</span><em>添加商品</em> </p> </a> </li>
                <?php } ?>
            </ul>
		</div>
        <a href="#" style="width: 80%;display: inline-block;text-align: center;background: #f1f2f8;line-height: 30px;margin: 10px 0px;border-radius: 10px;position: relative;left: 50%;transform: translateX(-50%);font-size: 12px;color: #9a9a9a;">更多</a>
	</div>
</section>
<?php if(empty($id)){?>
    <footer style="background-color:#FFF;">
        <ul class="cl">
            <li><a href="index.php">首页</a></li>
            <li><a href="fenlei.php">分类</a></li>
            <li><a href="baishe.php">拍</a></li>
            <li><a href="shopping.php">商城</a></li>
            <li><a href="member.php">我</a></li>
        </ul>
    </footer>
<?php } ?>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script type="text/javascript">
    $(function(){
        var $grid = $('.grid').masonry({
            itemSelector: '.video-box-item',
            columnWidth: '.grid-sizer',
            percentPosition: true
        });
        $grid.imagesLoaded().progress( function() {
            $grid.masonry('layout');
        });
        $(".del_goods").click(function(){
            if(confirm("确认删除此商品?")){
                $(".goods_link").removeAttr('href');
                var id = $(this).attr('web_id');
                $.ajax({
                    url: 'goods_ajax.php?way=delete',
                    type: "post",
                    data: {'id':id} ,
                    dataType: 'json',
                    success:function(res){
                        console.log(res);
                        if(res.status == 'y'){
                            layer.open({content: res.info,skin: 'msg',time: 2 });
                            location.href="https://5p8.fyh5p8.com/xiaochengxu/mem_goods.php";
                        }else{
                            layer.open({content: res.info,skin: 'msg',time: 2 });
                        }
                    }
                })
            }
        })

        $(".up_goods").click(function(){
            $(".goods_link").removeAttr('href');
            var id = $(this).attr('web_id');
            location.href='goods_edit.php?way=edit&id='+id+'&shop_son_id='+'<?php echo $shop_son_id; ?>';
        })
        $(".grls-menu-box li").click(function(){
    		$(this).addClass("cur").siblings().removeClass("cur");
    	});
    });
</script>
</body>
</html>
